#include <iostream>
#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <stack>

using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-6;
const double INF = 1e9 + 7;



int Min(int a, int b, int c)
{
	int m = a;
	if (m > b)
		m = b;
	if (m > c)
		m = c;
	return m;
}


int main()
{
	freopen("data.in", "r", stdin);

	int n, m;

	cin >> n >> m;

	if (n == 0 && m == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	vector<int> row(m, 0);
	vector<vector<int> > matrix(n, row);


	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> matrix[i][j];
		}
	}

	int** dp = new int*[n];
	for (int i = 0; i < n; ++i){
		dp[i] = new int[m];
		memset(dp[i], 0, sizeof(int)*(m));
	}


	for (int j = 0; j < m; ++j)
		if (matrix[0][j] == 1)
			dp[0][j] = 1;

	for (int i = 0; i < n; ++i)
		if (matrix[i][0] == 1)
				dp[i][0] = 1;

	
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < m; j++)
		{
			if (matrix[i][j] == 1)
			{
				dp[i][j] = Min(dp[i-1][j],dp[i][j-1], dp[i-1][j-1])+1;
			}
		}
	}
	
	int maxArea = dp[0][0];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (maxArea<dp[i][j])
			{
				maxArea = dp[i][j];
			}
				
		}

	}

	cout <<maxArea << endl;

	for (int i = 0; i < m; ++i)
		delete[] dp[i];
	delete[] dp;




	system("pause");
	return 0;
}